package com.quanyan.scheduler.task.tracker;

import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.tasktracker.Result;
import com.github.ltsopensource.tasktracker.runner.JobContext;
import com.github.ltsopensource.tasktracker.runner.JobRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xian-guo
 */
public class TaskJobRunner implements JobRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskJobRunner.class);
   /* @Autowired
    private TbUserService tbUserService;
*/
    @Autowired
    private JobRunnerA jobRunnerA;

    @Autowired
    private JobRunnerB jobRunnerB;

    @Override
    public Result run(JobContext jobContext) throws Throwable {
            LOGGER.debug("------TaskJobRunner执行了---------" + jobContext);
            Job job=jobContext.getJob();//对于需要执行多个任务的业务场景，可以使用这种方式
            String jobType=job.getParam("type");
            if("typeA".equals(jobType)){
                return jobRunnerA.run(jobContext);
            }else if ("typeB".equals(jobType)){
                return jobRunnerB.run(jobContext);
            }else {
                return new Result(Action.EXECUTE_SUCCESS, "-------no execute task---------------");
            }
    }

}
